//
//  OrderNoDataView.swift
//  列表无数据View
//
//  Created by 千策万划-mini on 2025/5/8.
//

import Foundation

class OrderNoDataView: UIView {
    
    var blockApplyClick:(() -> Void)?
    
    // MARK: - lazy
    lazy var imageLogo: UIImageView = {
        let result = UIImageView()
        result.widthHeight = XY(W(110), W(115))
        result.image = UIImage(named: "icon_order_nodata_logo")
        return result
    }()
    lazy var labelTitle: UILabel = {
        let result = UILabel()
        result.textColor = COLOR_WHITE()
        result.font = UIFont.customSemiBoldFont(size: 16)
        result.fitTitle("No Data Yet", variable: 0)
        return result
    }()
    lazy var labelContent: UILabel = {
        let result = UILabel()
        result.textColor = UIColor(hex: "#8977C3")
        result.font = UIFont.customMediumFont(size: 14)
        result.numberOfLines = 0
        result.textAlignment = .center
        result.fitTitle("From now on, create your own\nwonderful record!", variable: 0)
        return result
    }()
    lazy var btnApply: UIButton = {
        let result = UIButton()
        result.widthHeight = XY(W(98), W(40))
        result.setBackgroundImage(UIImage(named: "icon_order_nodata_apply"), for: .normal)
        result.tag = 1
        result.addTarget(self, action: #selector(btnClick(_:)), for: .touchUpInside)
        
        let label = OutlineLabel()
        label.resetView(
            title: "Apply",
            textColor: COLOR_WHITE(),
            font: UIFont.customSemiBoldFont(size: 16),
            shadowColor: UIColor(hex: "#004600"),
            outlineColor: UIColor(hex: "#1B4506")
        )
        label.centerXCenterY = XY(result.width/2, result.height/2)
        result.addSubview(label)
        return result
    }()
    
    
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.widthHeight = XY(SCREEN_WIDTH, 0)
        self.backgroundColor = .clear
        self.addSubView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 添加
    func addSubView() {
        addSubview(imageLogo)
        addSubview(labelTitle)
        addSubview(labelContent)
        addSubview(btnApply)
        resetView()
    }
    
    
    // MARK: - 点击事件
    @objc func btnClick(_ sender: UIControl) {
        feedback()
        sender.addClickAnimate()
        switch sender.tag {
        case 1:
            if let block = blockApplyClick {
                block()
            }
            break
        default:
            break
        }
    }
    
    // MARK: - 重置界面
    func resetView() {
        imageLogo.centerXTop = XY(SCREEN_WIDTH/2, 0)
        labelTitle.centerXTop = XY(SCREEN_WIDTH/2, imageLogo.bottom+W(14))
        labelContent.centerXTop = XY(SCREEN_WIDTH/2, labelTitle.bottom+W(7))
        btnApply.centerXTop = XY(SCREEN_WIDTH/2, labelContent.bottom+W(12))
        height = btnApply.bottom
    }
}
